<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('网店商品信息')" />
	<th:block th:include="include :: list-css" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
		.layui-form-radio {margin-top:0}
		.importTable{empty-cells:show;border-collapse:collapse;border-spacing:0;}
		.listext th{background:#eee;color:#3366cc;}
		.listext th,.listext td{border:solid 1px #ddd;text-align:left;padding:10px;font-size:14px;}
		
		#importProgress {z-index:20200202;background-color: #000;opacity: 0.3;display:none;}
		.importProgress {width:300px;z-index:20202222;position: fixed;top: 34%;left: 40%;display:none;}
		/* .layui-table-box{overflow-x: auto !important;}
		.layui-table-header{display: inline-block !important;} */
		tr img{width: 30px !important;height: 30px !important;margin: 0 2px;}
		.ishide{display: none;}
        .bagimg{z-index: 999;max-width:200px;border: 5px solid #23b971}
	</style>
</head>
<body>
<div class="ishide"><img class="bagimg" src=""/></div>
<div class="main-content">
	<div class="content-right">
		<div class="search-top">
			<span>查询条件</span>
			<a href="javascript:;" layadmin-event="flexible" class="menuBtn">
				<i class="layui-icon layui-icon-spread-left" id="LAY_app_flexible" style="color: #fff;"></i>
			</a>
		</div>
		<div class="panel layout-expand layui-expand-east">
		    <div class="panel-header">
		        <div class="panel-tool" style="text-align: center; width: 26px;height: 30px;line-height: 30px;">
		            <a href="javascript:;" layadmin-event="flexible" class="menuBtn">
		                <i class="layui-icon layui-icon-shrink-right" id="LAY_app_flexible" style="color: #fff;"></i>
		            </a>
		        </div>
		    </div>
		    <div class="panel-body panel-title" style="text-align: center; width: 26px;">查<br>询<br>条<br>件</div>
		</div>
       	<form class="layui-form">
			<th:block th:include="listinclude :: searchRight('page')" />
		</form>
   	</div>
    <div class="mid-content">
		<table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	</div>
</div>
<!-- 表格头部工作栏-->
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-table-tools sdhqbtn" lay-event="sdhqbtn" th:if="${extraButton.sdhqbtn}">
			<i class="dhicon dh-zu4491"></i> 手动获取
        </div>
		<div class="layui-btn layui-table-tools importbtn-bg" lay-event="exportbtn" shiro:hasPermission="hr:amazonshopproduct:export">
			<i class="dhicon dh-download"></i> 导出
        </div>
    </div>
</script>
<script type="text/html"  id="templet_mainImage">
	{{# if(d.mainImage){ }}
	   <img src="{{d.mainImage}}"/>
	{{# }else{ }}
	{{# } }}
</script>


<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: searchJS" />
<th:block th:include="listinclude :: list-templeat" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "hr/amazonshopproduct";
	var gridColumns = [[${gridColumns}]], 
		importFields =[[${importFields}]],
		extraButton = [[${extraButton}]],
		moduleTable =[[${moduleTable}]],
		ali1688EcpApiUrl = [[${ali1688EcpApiUrl}]],
		session=[[${session}]];
	/*]]>*/
</script>
<script type="text/javascript">
var element,thStr;
var fieldWidth = {},		//导入列表字段宽度
	filedRequired = {},		//导入列表必填字段
	dateFiled = [],			//导入列表日期字段
	hasNull = false;		//导入数据必填字段有空值
$.each(gridColumns.dictionaryForPageFieldList,function(i,v){
	fieldWidth[v.fields] = v.fieldFrontWidth
	if(v.fieldFrontRequired)filedRequired[v.fields] = v.fieldName;
	if(v.fieldFrontType == 't_date')dateFiled.push(v.fields);
})
var $,layer,laydate,form,table,wherestr={};
layui.use(['table','laydate','form','layer','jquery','element'], function () {
	$ = layui.$, layer = layui.layer,laydate = layui.laydate , form = layui.form, table = layui.table, element = layui.element;
	serachRender();//查询条件初始渲染集合
	changeDropdown('fSl');//导入窗口——税率下拉可编辑赋事件
	$.tablelist.init({
		elem: '#dhtable'
		,modalName: "产品信息"
		,url: prefix + '/list'
		,updateUrl: prefix + "/edit?guid={id}"
		,totalRow: gridColumns.totalRow
		,cols: [gridColumns.gridBody]
		,toolbar: '#toolbar'
		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
		,height:'full-65'
        ,parseData: function(res){ //res 即为原始返回的数据
			var objpage=sessionStorage.getItem(moduleTable+'checkdata')
			if(objpage){
				objpage=JSON.parse(objpage)
				res.data.map((v,i)=>{
					objpage.map((n,m)=>{
						 if(v.guid==n.guid){
							v.LAY_CHECKED=true
						 }
					})
				})
			}
		}
		,done:function(){
			firstimg()
		}
	});
    
	//监听排序事件 
	table.on('sort(ftable)', function(obj){
		$.tablelist.sort('dhtable',obj);
	});

	//多选复选框
    sessionStorage.setItem(moduleTable+'checkdata','')
    table.on('checkbox(ftable)', function(obj){
		var objpage=sessionStorage.getItem(moduleTable+'checkdata')
		if(obj.type=='all'){//判断是否全选
			var objdata=table.checkStatus('dhtable')
			objdata=objdata.data
			if(obj.checked){//判断是否选中
				if(objpage){
					objpage=JSON.parse(objpage)
					objpage=objpage.concat(objdata)
					objpage=newData(objpage)
				}else{
					objpage=objdata
				}
			}else{
				var objpage=JSON.parse(objpage)
				var deldata=table.cache.dhtable
				objpage=delData(objpage,deldata)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
		}else{//点击复选框
			if(objpage){
				objpage=JSON.parse(objpage)
				if(obj.checked){
					objpage.push(obj.data)
				}else{
					objpage.map((v,i)=>{
						if(v.guid==obj.data.guid){
							objpage.splice(i,1)
						}
			    	})
			    }
			}else{
				objpage=[]
				objpage.push(obj.data)
			}
			sessionStorage.setItem(moduleTable+'checkdata',JSON.stringify(objpage))
		}
	});


	//头工具栏事件
	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
	   		case 'exportbtn':
		   		$.ajax({
		   		    url: '/hr/amazonshopproduct/export',
		   		    type: 'GET',
		   		    data: getWherestr(),
		   		    dataType: 'json',
		   		    beforeSend: function(){
			   			showloadings(true);
		   		    },
		   		    success: function(result){
		   		    	if (result.code == 0) {
					        window.location.href = ctx + "common/download?fileName=" + encodeURIComponent(result.msg) + "&delete=" + true;
					        parent.$('.page-loading').hide();//页面进行了跳转刷新，需要手动关闭页面的加载动画
						} else if (result.code == web_status.WARNING) {
		                   $.modal.alertWarning(result.msg)
		            	} else {
							$.modal.alertError(result.msg);
						}
				   		showloadings(false);
		   		    }
		   		});
	   		break;
			case 'sdhqbtn':
			     var data=sessionStorage.getItem(moduleTable + 'checkdata');
				 if(data){
					data=JSON.parse(data)
					if(data.length==0) return layer.msg('请勾选手动获取的数据');
					var prodGuids=[]
					data.map((res)=>{
						prodGuids.push(res.guid)
					})
					prodGuids=prodGuids.join(',')
					showloadings(true);
					$.post(ali1688EcpApiUrl+'/api/amazon/getAmazonShopProductInfo',{prodGuids,userId:session.userId},function(res){
						layer.msg(res.msg)
						sessionStorage.removeItem(moduleTable + 'checkdata');
                        if(res.code==0){
							setTimeout(()=>{
								showloadings(false);
								location.reload();
							},800)
						}else{
							showloadings(false);
						}
                    });
				 }else{
                    layer.msg('请勾选手动获取的数据')
				 }
				
			break;
 	    };
 	});

 });




</script>
</body>
</html>